<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <my-parent></my-parent>
  </div>
</body>
<template id="parent">
  <div>
    <h1>父组件</h1>
    <my-child />
  </div>
</template>
<template id="child">
  <div>
    <h4>子组件</h4>
  </div>
</template>
<script src="lib/vue.js"></script>
<script>
  const Child = {
    template: '#child',
    mounted () {
      console.log(this.$root.test)
    }
  }
  const Parent = {
    template: '#parent',
    components: {
      MyChild: Child
    }
  }

  new Vue({
    el: '#app',
    data: {
      test: '测试'
    },
    components: {
      MyParent: Parent
    }
  })
</script>
</html>